import ekf_testv6 as ekf
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.transforms as mtransforms

fig, ax= plt.subplots(2, 4, figsize=(10,8), gridspec_kw={ "hspace": 0.3, "wspace": 0.3})

typredict=["GMST","OHCA"]

allqqyker=np.array(ekf.qqykerall)
axlabels=[['a)','b)','c)','d)'],['e)','f)','g)','h)']]

for i in [0,1]:
    ax[i,0].set_ylabel("Probability Density")
    for j in range(4):
        sd=j*50
        if j==0:
           sd=1 
        ed=(j+1)*50
        if j==3:
            ed=ed-50+24
        
        ax[i,j].plot(ekf.xnorm,np.mean(allqqyker[sd:ed,i,:],axis=0), color=ekf.colorekf)
        ax[i,j].plot(ekf.xnorm,ekf.ynorm, color=ekf.pcolor)
        if i==0:
            ax[i,j].set_xlabel("Pred. Std Dev $\sqrt{s^T_{t}}$",labelpad=-3)
        else:
            ax[i,j].set_xlabel("Pred. Std Dev $\sqrt{s^H_{t}}$",labelpad=-3)
        ax[i,j].set_title(typredict[i]+": "+str(sd+1850)+"-"+str(ed+1850-1))
        trans = mtransforms.ScaledTranslation(-15/72, 5/72, fig.dpi_scale_trans) #-20/72, 7/72
        ax[i,j].text(0.0, 1.0, axlabels[i][j], transform=ax[i,j].transAxes + trans, fontsize='large', va='bottom')
        
fig.suptitle("EBM-KF Residuals Over Time")
plt.show()


